/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:    cmrc.h
**  Author:  Michael
**  Date:    03/20/2014
**
**  Purpose:
**    common resource defines.
*/

#ifndef __CM_RC_H__
#define __CM_RC_H__

#ifdef __cplusplus
extern "C" {
#endif				/* __cplusplus */

/* Include files. */

#include "common.h"

/* Macro constant definitions. */

#define CONFIG_CM_SOCKET				"/var/sysmgr_cm.socket"
#define CM_MSG_BUFF_SIZE				(10240)

#define CM_SESSION_NAME_SIZE			(64)
#define CM_SESSION_ID_NONE				(0)
#define CM_INVALID_FD					(-1)

/* Type definitions. */

	enum {
		eCM_MODULE_SYS_ADMIN,
		eCM_MODULE_DATA_PATH,
		eCM_MODULE_EXTRA_APP,
	};

	enum {
		eCM_DIR_CALL,
		eCM_DIR_REPLY,
	};

	enum {
		eCM_OPERATION_CREATE_SESSION,
		eCM_OPERATION_DESTORY_SESSION,
		eCM_OPERATION_REQUEST,
		eCM_OPERATION_NOTIFY,
	};

	typedef struct {
		unsigned char opt;
		unsigned char dir;
		unsigned int sessionid;
		unsigned int transid;
		unsigned int ret;
		unsigned int opt_body_len;
		unsigned int opt_counter;
	} tcm_header;

	typedef struct {
		tcm_header header;
		unsigned char opt_body[0];
	} tcm_msg;

	typedef struct {
		unsigned int module;
		unsigned int req_body_len;
		unsigned char mod_req_body[0];
	} tcm_req_body;

	typedef struct {
		unsigned int module;
		unsigned int ret;
		unsigned int rsp_body_len;
		unsigned char mod_rsp_body[0];
	} tcm_rsp_body;

	typedef struct {
		char from[CM_SESSION_NAME_SIZE];
	} tcm_session_body;

	typedef struct {
		unsigned int module;
		unsigned char mod_notify_body[0];
	} tcm_notify_body;

	typedef struct {
		char name[CM_SESSION_NAME_SIZE];
		unsigned int id;
		unsigned int transid;
		int conn_fd;
		long int timestamp;
		struct sockaddr_un addr;
		socklen_t addr_len;
		struct list_head sibling;
		unsigned int buf_len;
		unsigned int msg_len;
		tcm_msg *msg_buf;
		e_bool shutdown;
	} tcm_session;

/* External function declarations. */

/* Macro API definitions. */

/* Global variable declarations. */

#ifdef __cplusplus
}				/* extern "C" */
#endif				/* __cplusplus */
#endif				/* __CM_RC_H__ */
